using System.Collections.Generic;
using System.Linq;

namespace PokerStar.Core
{
    public class GameResultCollection
    {
        private readonly IEnumerable<Player> _players;

        public GameResultCollection(IEnumerable<Player> players)
        {
            _players = players;
        }

        public IEnumerable<Player[]> GetRates()
        {
            //foreach (var group in _players.OrderByDescending(p => p.Result))
            //{
            //    //yield return new[] { player };
            //    //var 
            //    //var players = new[] { group.First() };
            //}

            var players = _players.OrderByDescending(p => p.Result).ToArray();
            for (int i = 0, len = players.Length; i < len; )
            {
                var group = new List<Player> { players[i] };
                for (int j = i + 1; j < len; j++)
                {
                    if (players[j].Result.CompareTo(players[i].Result) == 0)
                    {
                        group.Add(players[j]);
                    }
                    else
                    {
                        break;
                    }
                }
                i += group.Count;
                yield return group.ToArray();
            }
        }
    }
}